package no.progark.copter;

import no.progark.helikopter.R;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Copter{

	private boolean collision = false;
	private int x; 
	private int y; 
	private Direction dir;
	private Paint textPaint = new Paint();
	public int imageID;
	private int imgleft, imgright, imgup, imgdown;
//	Bitmap helicopter = BitmapFactory.decodeResource(getResources(), initImage(dir));
	private int imgleft2, imgright2, imgup2, imgdown2;
	public Copter(Direction d, boolean collision, int maxX, int maxY, int imgleft, int imgright, int imgup, int imgdown){
		dir = d;
		x = (int) (20 + (Math.random() * maxX));
		y = (int) (20 + (Math.random() * maxY));
		
		this.imgleft = imgleft;
		this.imgright = imgright;
		this.imgup = imgup;
		this.imgdown = imgdown;
		imageID = initImage();
	}
	
	public void setImages(int left, int right, int up, int down){
		imgleft2 = left;
		imgright2 = right;
		imgup2 = up;
		imgdown2 = down;
	}
		
	public void drawCoords(Canvas c, int px, int py, int color){
	textPaint.setColor(color);
	textPaint.setStyle(Paint.Style.FILL);
	textPaint.setTextSize(10);
	c.drawText(""+x+","+y+"", px, py, textPaint);
	}
	
	public int initImage(){
		int res = 0;
		switch (dir.getDirectionCharacter()) {
		case 'u':
			res = imgup;
			break;
		case 'd':
			res = imgdown;
			break;
		case 'l':
			res = imgleft;
			break;
		case 'r':
			res = imgright;
			break;
		}
		return res;
	}
	
	public int getNextImage(){
		int result = 0;
		if(imageID == imgdown)result = imgdown2;
		else if(imageID == imgdown2)result = imgdown;
		else if(imageID == imgup)result = imgup2;
		else if(imageID == imgup2)result = imgup;
		else if(imageID == imgleft)result = imgleft2;
		else if(imageID == imgleft2)result = imgleft;
		else if(imageID == imgright)result = imgright2;
		else if(imageID == imgright2)result = imgright;
		else System.out.println("No matching image! CHeck getNExtImage function!");
		imageID = result;
		return result;
	}
	
	
	public boolean isCollision() {
		return collision;
	}

	public void setCollision(boolean collision) {
		this.collision = collision;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Direction getDir() {
		return dir;
	}

	public void setDir(Direction dir) {
		this.dir = dir;
	}

	public Paint getTextPaint() {
		return textPaint;
	}

	public void setTextPaint(Paint textPaint) {
		this.textPaint = textPaint;
	}
	
}
